package tf2pickup.listeners;

import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.events.MessageEvent;
import org.pircbotx.PircBotX;

import tf2pickup.Config;

/**
 * This class takes care of all upcoming commands that require a static answer.
 * - mumble-info
 * - maps-info
 * - help-info
 * @author Philipp Preß
 */
public class PrintPlainText extends ListenerAdapter<PircBotX> {

    private Config cfg;

    /**
     * Creates a new Listener that will respond by pm-ing the user with 
     * plain-text info when the commands !mumble, !maps, !help are sent in the
     * channel.
     * @param config configuration-file of the bot.
     */
    public PrintPlainText(Config config) {
        this.cfg = config;
    }

    @Override
    /**
     * gets executed when a message is sent to the channel. reacts to the 
     * commands !mumble, !maps, !help.
     */
    public void onMessage(MessageEvent<PircBotX> event) {
        String message;
        
        message = event.getMessage().toLowerCase();
        if (message.equals("!mumble")) {
            event.getBot().sendMessage(event.getUser(), "Mumble-info:");
            event.getBot().sendMessage(event.getUser(), "Mumble-host: " + cfg.mumbleServer);
            event.getBot().sendMessage(event.getUser(), "Mumble-port: " + cfg.mumblePort);
            if (cfg.mumblePassword != null) {
                event.getBot().sendMessage(event.getUser(), "Mumble-password: " + cfg.mumblePassword);
            }
            return;
        } else if (message.equals("!maps")) {
            event.getBot().sendMessage(event.getUser(), "Maps:");
            event.getBot().sendMessage(event.getUser(), 
                    cfg.maps.toString().toLowerCase().substring(1, cfg.maps.toString().length() - 2));
            return;
        } else if (message.equals("!help")) {
           event.getBot().sendMessage(event.getUser(), "Help:");
           event.getBot().sendMessage(event.getUser(), "Type '!medic' to add yourself as a medic.");
           event.getBot().sendMessage(event.getUser(), "Type '!soldier' to add yourself as a soldier.");
           event.getBot().sendMessage(event.getUser(), "Type '!demoman' to add yourself as a demoman.");
           event.getBot().sendMessage(event.getUser(), "Type '!scout' to add yourself as a scout.");
           event.getBot().sendMessage(event.getUser(), "Type '!map <MAPNAME>' to vote for a map.");
           event.getBot().sendMessage(event.getUser(), "Type '!remove' to remove yourself from the pickup.");
           event.getBot().sendMessage(event.getUser(), "Type '!mumble' to get the mumble-info.");
           event.getBot().sendMessage(event.getUser(), "Type '!maps' to get a list of all votable maps.");
           event.getBot().sendMessage(event.getUser(), "Type '!help' to get this help-message.");
           event.getBot().sendMessage(event.getUser(), "Visit http://code.google.com/p/tf2pickup/wiki/PlayerManual "
                    + " for more information.");
            return;
        }

    }
}
